#define _CRT_SECURE_NO_WARNINGS   1

#include<iostream>

using namespace std;
int w[40], f[20010];
int main(){
	int n, v;
	cin >> v;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> w[i];
	for (int i = 1; i <= n; i++)
	for (int j = v; j >= w[i]; j--)
	if (f[j]<f[j - w[i]] + w[i]) 
		f[j] = f[j - w[i]] + w[i];
	cout << v - f[v] << endl;
	return 0;
}